﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThouShaltNotBrick.Models;
using Microsoft.Xna.Framework.Content;

namespace ThouShaltNotBrick.PipelineExtension.Readers
{
    public sealed class LevelContentTypeReader : ContentTypeReader<LevelData>
    {
        #region Overriden Methods
        protected override LevelData Read(ContentReader pInput, LevelData pExistingInstance)
        {
            // NAME (string)
            // NUMBER OF BRICKS (int)
            //   TYPE (string)
            //   ROW (int)
            //   COLUMN (int)
            //   INITIAL_STATE (int)

            string levelName = pInput.ReadString();

            int numBricks = pInput.ReadInt32();
            List<BrickData> brickList = new List<BrickData>(numBricks);
            for (int i = 0; i < numBricks; i++)
            {
                string type = pInput.ReadString();
                int row = pInput.ReadInt32();
                int column = pInput.ReadInt32();
                int initialState = pInput.ReadInt32();

                BrickData brick = new BrickData(type, row, column, initialState);
                brickList.Add(brick);
            }

            LevelData level = new LevelData(levelName, brickList);
            return level;
        }
        #endregion
    }
}